using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Xml;

using Pampa.WebControls;
using Pampa.CRUD.UI.CustomControls;

namespace Pampa.CRUD.Configuration
{
    public class DateItem : EditItem
    {
        DatePicker datePicker = new DatePicker();

        public DateItem() : base()
        {
        }

        public DateItem(DateItem sourceItem) : base(sourceItem)
        {
        }

        #region Properties

        public override Type ValueTypeDefault
        {
            get { return typeof(System.DateTime); }
        }

        public override ItemType ItemType
        {
            get { return ItemType.DatePicker; }
        }

        public DatePickerType Type
        {
            get { return datePicker.Type; }
            set { datePicker.Type = value; }
        }

        public override Control Control
        {
            get
            {
                datePicker.CssClass = "datePicker";
                datePicker.Enabled = this.Enabled;
                datePicker.OnClientChange = "if(typeof(Relationship_EvalOnChange) != \\\"undefined\\\") Relationship_EvalOnChange";

                if (this.Value != null)
                    datePicker.Date = DateTime.Parse(this.Value.ToString());

                return datePicker;
            }
        }

        #endregion

        #region Public Functions

        public override VisibleItem Clone()
        {
            return new DateItem(this);
        }

        public override void LoadXml(XmlNode node)
        {
            try
            {
                base.LoadXml(node);

                if (node.Attributes["Type"] != null)
                    this.Type = (DatePickerType)Enum.Parse(typeof(DatePickerType), node.Attributes["Type"].Value);
            }
            catch (Exception ex)
            {
                throw new Pampa.CRUD.Exceptions.ConfigurationException("Item " + this.Id + " mal definido.", ex);
            }
        }

        #endregion
    }
}
